package com.source.multithread.atomicc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author wengqy
 * @Date 2020/12/25
 */
public class AtomicIntegerABA {
       static AtomicInteger  atomicInteger  = new AtomicInteger(5);
    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(atomicInteger.compareAndSet(5, 100));
            System.out.println(atomicInteger.get());
            System.out.println(atomicInteger.compareAndSet(100, 5));
            System.out.println(atomicInteger.get());
        },"AA").start();


        new Thread(()->{

            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(atomicInteger.compareAndSet(5, 888));
            System.out.println(atomicInteger.get());
        },"BB").start();






    }
}
